package com.yungu.swift.order.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.yungu.swift.assets.driver.service.DriverStatusCycleService;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.lbs.service.LocationService;
import com.yungu.swift.order.dao.OrderTrackMileageMapper;
import com.yungu.swift.order.model.dto.OrderTrackMileageDto;
import com.yungu.swift.order.service.OrderTrackMileageService;
import com.yungu.swift.order.thread.driver.status.DriverStatusCycleRunnable;
import com.yungu.swift.order.utils.ThreadExecutorUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * OrderTrackMileageServiceImpl
 **/

@Service
public class OrderTrackMileageServiceImpl extends BaseServiceImpl<OrderTrackMileageDto> implements OrderTrackMileageService {

    @Autowired
    private OrderTrackMileageMapper orderTrackMileageMapper;
    @Reference
    private LocationService locationService;
    @Reference
    private DriverStatusCycleService driverStatusCycleService;

    @Override
    public IMapper<OrderTrackMileageDto> getMapper() {
        return orderTrackMileageMapper;
    }

    @Override
    public ResponseData<Integer> addBatch(List<OrderTrackMileageDto> list) {
        return ResponseData.buildSuccessResponse(orderTrackMileageMapper.addBatch(list));
    }

    @Override
    public void statusCycle(String appid, String driverUuid, String orderUuid, String carUuid, int action) {
        // 因为与主逻辑无关 所以异步统计里程
        ThreadExecutorUtils.execute(new DriverStatusCycleRunnable(
                driverStatusCycleService,
                locationService,
                appid,
                driverUuid,
                orderUuid,
                carUuid,
                action));
    }

}